
var form_syslog_preinit = function(){
    jQuery('#search_name').searchbox(
    {
       searcher:function(value,name)
       {  
            jQuery('#manage_users').datagrid('reload');
       } 
    }
    )
}

var form_onBeforeLoad = function(param)
{   
    jQuery(this).datagrid('options').url =__Manager_BuildUrl() ;
};
var form_onClickRow = function(rowIndex, rowData)
{   
    if(rowData.is_locked==1)
    {
    $('#lock_user').linkbutton('disable');
    $('#unlock_user').linkbutton('enable');
    }
    else
    {
    $('#lock_user').linkbutton('enable');
    $('#unlock_user').linkbutton('disable');
    }
};
function __Manager_BuildUrl(){
    var url=__FormHelper_GetActionLink(); 
    var options=__FormHelper_GetGridObject().datagrid("options");
    var search_name=jQuery.trim(jQuery("#search_name").searchbox("getValue"));
    if(search_name!='')
    {
     url += "&search_name="+search_name;   
    }
    if (options.sortName != null)
    {
        url+="&sortName="+encodeURI(options.sortName)+"&sortOrder="+options.sortOrder;
    }
    return url;

}
//http://newlaw/english/administrationmodule/umgr_lockuser/id/48/value/1/
//http://newlaw/english/administrationmodule/umgr_editprofile/id/48/
//http://newlaw/english/administrationmodule/umgr_clearpass/id/48/
function __Clearpass()
{
   var node = __FormHelper_GetGridObject().datagrid('getSelected');
   var temp=Math.random()*9999;
    if (node){
        if (!confirm("Are you sure clear password for this user?"))
            return;
            _abpv_showLoading();
        // call ajax
        jQuery.post("/index.php", {
            module: 'administrationmodule',
            action: 'umgr_clearpass',
            ajax_action: '1',
            id: node.id,
            src: __FormHelper_GetSrc(),
            t: temp
        }, function(param)
        {
            __FormHelper_GetGridObject().datagrid('reload');
            _abpv_hideLoading();
        }
        );
       __FormHelper_GetGridObject().datagrid('clearSelections');
    }
}
function __Lock()
{
   var node = __FormHelper_GetGridObject().datagrid('getSelected');
   var temp=Math.random()*9999;
    if (node){
        if (!confirm("Are you sure lock this user?"))
            return;
            _abpv_showLoading();
        // call ajax
        jQuery.post("/index.php", {
            module: 'administrationmodule',
            action: 'umgr_lockuser',
            ajax_action: '1',
            id: node.id,
            src: __FormHelper_GetSrc(),
            value:1,
            t: temp
        }, function(param)
        {
            __FormHelper_GetGridObject().datagrid('reload');
            _abpv_hideLoading();
        }
        );
       __FormHelper_GetGridObject().datagrid('clearSelections');
    }
}
function __UnLock()
{
    _abpv_showLoading();
   var node = __FormHelper_GetGridObject().datagrid('getSelected');
    if (node){
        // call ajax
        jQuery.post("/index.php", {
            module: 'administrationmodule',
            action: 'umgr_lockuser',
            ajax_action: '1',
            id: node.id,
            src: __FormHelper_GetSrc(),
            value:0,
        }, function(param)
        {
            _abpv_hideLoading();
            __FormHelper_GetGridObject().datagrid('reload');
        }
        );
       __FormHelper_GetGridObject().datagrid('clearSelections');
    }
    
}
function __Add()
{
    var src=__FormHelper_GetSrc();
    var url="/index.php?module=administrationmodule&action=umgr_editprofile&id=0";
    window.location.href=url;
}

function __Edit(table_selector){
    
    var node = __FormHelper_GetGridObject().datagrid('getSelected');
    if (node){
        var url="/index.php?module=administrationmodule&action=umgr_editprofile&id="+node.id;
        window.location=url;
    }
    // 
}

function __Delete(){

   var node = __FormHelper_GetGridObject().datagrid('getSelected');
    if (node){
        if (!confirm("Are you sure deleting this user?"))
            return;
        // call ajax
        _abpv_showLoading();
        jQuery.post("/index.php", {
            module: 'administrationmodule',
            action: 'umgr_delete',
            ajax_action: '1',
            id: node.id,
            src: __FormHelper_GetSrc(),
        }, function(param)
        {
            __FormHelper_GetGridObject().datagrid('reload');
            _abpv_hideLoading();
        }
        );
       __FormHelper_GetGridObject().datagrid('clearSelections');
    }

}

function _abpv_showLoading(){
    jQuery('#abpv_loadingDiv').fadeIn();
}

function _abpv_hideLoading(){
    jQuery('#abpv_loadingDiv').fadeOut();
}
jQuery.fn.centerScreen = function(loaded) { 
            var obj = this; 
            obj.css('top', $(window).height()/2- this.height()/2); 
            obj.css('left', $(window).width()/2- this.width()/2); 
            return;
            if(!loaded) { 
                obj.css('top', $(window).height()/2- this.height()/2); 
                obj.css('left', $(window).width()/2- this.width()/2); 
                $(window).resize(function() 
                    { obj.centerScreen(!loaded); }); 
            } else { 
                obj.stop(); 
                obj.animate({ top: $(window).height()/2 - this.height()/2, left: $(window).width()/2-this.width()/2}, 200); 
            } 
        };

        jQuery("#abpv_loadingDiv").centerScreen(true);
        $(window).bind('resize', function() {
                jQuery("#abpv_loadingDiv").centerScreen(false);
        });
        $(window).bind('scroll', function() {
                jQuery("#abpv_loadingDiv").centerScreen(false);
        });    
